
Imports cmplib01

Public Class Iconographer

    Shared Function ChitIcon(ByRef chit As ChitMember, ByRef mapper As cCampaignerMapMaker, Optional ByVal forReplay As Boolean = False, Optional ByVal histo As HistoricalEntry = Nothing, Optional ByVal forEnemy As Boolean = False) As Bitmap
        '// if displayed = false then don't show the icon, it can't be seen

        Try
            '// we default to the current detection status and only overwrite it if we're doing for replay, in which case, we use the historical data
            Dim stat As cmplib01.ChitDetectionLevel_cdl = chit.detectionLevelThisTurn

            If forReplay Then stat = histo.detectionStatus

            If forReplay = True Then
                If histo.unitStatus = GroundUnitStatus_cgd.Disbanded Then Return mapper.CampaignerImages.disbanded
            Else
                If chit.Status = GroundUnitStatus_cgd.Disbanded Then Return mapper.CampaignerImages.disbanded
            End If

            If chit.Status = GroundUnitStatus_cgd.Disbanded Then
                Dim bmp As Bitmap = mapper.CampaignerImages.disbanded
                Return bmp
            End If

            If forEnemy = False Then
                '// really, we always show the correct icon, unless he's DEAD.
                If chit.Status = GroundUnitStatus_cgd.Dead Then
                    Dim bmp As Bitmap = mapper.CampaignerImages.deadFriendly
                    bmp.MakeTransparent(Color.Magenta)
                    Return bmp
                Else
                    If chit.UnitType = GroundChitClass_cgd.Objective Then
                        Return DirectCast(chit, InstallationChit).ptrInstallation.Icon(0)
                    Else
                        Return chit.icon
                    End If
                End If
            End If

            '// down here, there are no friendlies.


            '// test for dead unit
            If chit.Status = GroundUnitStatus_cgd.Dead Then
                Dim bmp As Bitmap = mapper.CampaignerImages.deadEnemy
                bmp.MakeTransparent(Color.Magenta)
                Return bmp
            End If


            '// otherwise, use detection status
            Select Case stat
                Case Is = ChitDetectionLevel_cdl.Dead : Return mapper.CampaignerImages.deadEnemy
                Case Is = ChitDetectionLevel_cdl.Undetected
                    Return Nothing
                Case Is <= ChitDetectionLevel_cdl.Detected_high
                    '// this is the kwestshun mark
                    Return mapper.CampaignerImages.spottedEnemy
                Case Is >= ChitDetectionLevel_cdl.Spotted
                    '// return the actual icon I guess
                    If chit.UnitType = GroundChitClass_cgd.Objective Then
                        Return DirectCast(chit, InstallationChit).ptrInstallation.Icon(0)
                    Else
                        Return chit.icon
                    End If

                Case Else
                    Return Nothing
            End Select

        Catch ex As Exception
            Return mapper.CampaignerImages.unknownIcon
        End Try

    End Function

End Class

